<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>分销推送平台</title>

    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet" />
    <link th:href="@{/font-awesome/css/font-awesome.css}" rel="stylesheet" />

    <!-- Toastr style -->
    <link th:href="@{/css/plugins/toastr/toastr.min.css}" rel="stylesheet"/>

    <link th:href="@{/css/style.css}" rel="stylesheet" />

    <!-- summernote style -->
    <link th:href="@{/css/plugins/summernote/summernote.css}" rel="stylesheet" />
    <link th:href="@{/css/plugins/summernote/summernote-bs3.css}" rel="stylesheet" />

</head>

<body>

<div id="wrapper">
    <nav class="navbar-default navbar-static-side" role="navigation" th:include="nav :: navigation"></nav>
    <div id="page-wrapper" class="gray-bg">
        <div class="border-bottom" th:include="header :: headerTop"></div>
        <div class="row wrapper border-bottom white-bg page-heading" th:fragment="headerNav">
            <div class="col-lg-10">
                <h2>接入配置管理</h2>
                <ol class="breadcrumb">
                    <li>
                        <a th:href="@{/main/dashboard}">首页</a>
                    </li>
                    <li>
                        <a>配置管理</a>
                    </li>
                    <li class="active">
                        <strong>新增接入配置</strong>
                    </li>
                </ol>
            </div>
            <div class="col-lg-2">
            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">



            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>新增接入配置</h5>
                            <div class="ibox-tools">
                                <a class="collapse-link">
                                    <i class="fa fa-chevron-up"></i>
                                </a>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <form id="formTag" action="editNews" method="POST" class="form-horizontal" enctype="multipart/form-data">
                                <input id="id" type="hidden" th:value="${newsAccessDO.id}"/>
                                <input id="token" type="hidden" th:value="${newsAccessDO.token}"/>

                                <div class="form-group"><label class="col-sm-2 control-label">接收方名称：</label>
                                    <div class="col-sm-10">
                                        <input id="name" th:value="${newsAccessDO.name}" type="text" class="form-control" />
                                    </div>
                                </div>
                                <div class="form-group"><label class="col-sm-2 control-label">推送接口：</label>
                                    <div class="col-sm-10">
                                        <input id="pushUrl" th:value="${newsAccessDO.pushUrl}" type="text" class="form-control" />
                                    </div>
                                </div>
                                <div class="form-group"><label class="col-sm-2 control-label">拉取频率：</label>
                                    <div class="col-sm-10">
                                        <input id="threshold" th:value="${newsAccessDO.threshold}" type="text" class="form-control" />
                                    </div>
                                </div>
                                <div class="form-group"><label class="col-sm-2 control-label">开启状态：</label>
                                    <div class="col-sm-10">
                                        <select name="opened" id="opened" class="form-control" >
                                            <option value="">--请选择优先级--</option>
                                            <option value="1" th:selected="${newsAccessDO.opened} == 1">开启</option>
                                            <option value="0" th:selected="${newsAccessDO.opened} == 0">关闭</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group"><label class="col-sm-2 control-label">接收类型：</label>
                                    <div class="col-sm-10">
                                        <select name="receiveType" id="receiveType" class="form-control" >
                                            <option value="">--请选择接收类型--</option>
                                            <option value="1" th:selected="${newsAccessDO.receiveType} == 1">推送</option>
                                            <option value="2" th:selected="${newsAccessDO.receiveType} == 2">拉取</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group"><label class="col-sm-2 control-label">推送类型：</label>
                                    <div class="col-sm-10">
                                        <select name="pushType" id="pushType" class="form-control" >
                                            <option value="">--请选择推送类型--</option>
                                            <option value="1" th:selected="${newsAccessDO.pushType} == 1">HTTP</option>
                                            <option value="2" th:selected="${newsAccessDO.pushType} == 2">TCP</option>
                                            <option value="3" th:selected="${newsAccessDO.pushType} == 3">RPC</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group"><label class="col-sm-2 control-label">转换器：</label>
                                    <div class="col-sm-10">
                                        <select name="converterType" id="converterType" class="form-control" >
                                            <option value="">--请选择转换器--</option>
                                            <option value="1" th:selected="${newsAccessDO.converterType} == 1">json</option>
                                            <option value="2" th:selected="${newsAccessDO.converterType} == 2">xml</option>
                                            <option value="3" th:selected="${newsAccessDO.converterType} == 3">form</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group"><label class="col-sm-2 control-label">优先级：</label>
                                    <div class="col-sm-10">
                                        <select name="priority" id="priority" class="form-control" >
                                            <option value="">--请选择优先级--</option>
                                            <option value="1"  th:selected="${newsAccessDO.priority} == 1">1</option>
                                            <option value="2"  th:selected="${newsAccessDO.priority} == 2">2</option>
                                            <option value="3"  th:selected="${newsAccessDO.priority} == 3">3</option>
                                            <option value="4"  th:selected="${newsAccessDO.priority} == 4">4</option>
                                            <option value="5"  th:selected="${newsAccessDO.priority} == 5">5</option>
                                            <option value="6"  th:selected="${newsAccessDO.priority} == 6">6</option>
                                            <option value="7"  th:selected="${newsAccessDO.priority} == 7">7</option>
                                            <option value="8"  th:selected="${newsAccessDO.priority} == 8">8</option>
                                            <option value="9"  th:selected="${newsAccessDO.priority} == 9">9</option>
                                            <option value="10"  th:selected="${newsAccessDO.priority} == 10">10</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>

                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-2">
                                        <button id="submitButton" class="btn btn-primary" type="button">&nbsp;&nbsp;&nbsp;&nbsp;提&nbsp;&nbsp;&nbsp;&nbsp;交&nbsp;&nbsp;&nbsp;&nbsp;</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div class="footer" th:include="footer :: copyright"></div>
    </div>
</div>

<!-- Mainly scripts -->
<script th:src="@{/js/jquery-2.1.1.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<script th:src="@{/js/plugins/metisMenu/jquery.metisMenu.js}"></script>
<script th:src="@{/js/plugins/slimscroll/jquery.slimscroll.min.js}"></script>

<!-- Peity -->
<script th:src="@{/js/plugins/peity/jquery.peity.min.js}"></script>

<!-- Custom and plugin javascript -->
<script th:src="@{/js/inspinia.js}"></script>
<script th:src="@{/js/plugins/pace/pace.min.js}"></script>
<script th:src="@{/js/plugins/sweetalert/sweetalert.min.js}"></script>
<link th:href="@{/css/plugins/sweetalert/sweetalert.css}" rel="stylesheet" type="text/css" />
<!-- common -->
<script th:src="@{/js/common.js}"></script>
<script th:src="@{/js/bms-util.js}"></script>

<!-- SUMMERNOTE -->
<script th:src="@{/js/plugins/summernote/summernote.min.js}"></script>


<script th:inline="javascript">
    $(document).ready(function () {
        //提交
        $("#submitButton").click(function(){
            if($("#name").val() == ""){
                sweetAlert("请输入接收方名称", "", "error");
                return;
            }
            if(isEmpty($("#pushUrl").val())){
                sweetAlert("请填写推送接口地址", "", "error");
                return;
            }
            if(isEmpty($("#threshold").val())){
                sweetAlert("请填写推送频率", "", "error");
                return;
            }
            if(isEmpty($("#opened").val())){
                sweetAlert("请选择消息开启状态", "", "error");
                return;
            }
            if(isEmpty($("#receiveType").val())){
                sweetAlert("请选择接收类型", "", "error");
                return;
            }
            if(isEmpty($("#pushType").val())){
                sweetAlert("请选择推送类型", "", "error");
                return;
            }
            if(isEmpty($("#converterType").val())){
                sweetAlert("请选择转换器", "", "error");
                return;
            }
            if(isEmpty($("#priority").val())){
                sweetAlert("请选择消息优先级", "", "error");
                return;
            }
            var newsAccessDO = {
                id : $("#id").val(),
                token : $("#token").val(),
                name : $("#name").val(),
                receiveType : $("#receiveType").val(),
                pushType : $("#pushType").val(),
                pushUrl : $("#pushUrl").val(),
                opened : $("#opened").val(),
                converterType : $("#converterType").val(),
                priority : $("#priority").val(),
                threshold : $("#threshold").val()
            };
            bms.requestAjaxPost("editNews",JSON.stringify(newsAccessDO),
                function(response){
                    window.location.href = "list";
                },function(response){
                    toastr.error(response.resMsg,'提示');
                });
        });
    });
</script>

</body>

</html>
